﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MailSortSettingRepository.cs" company="DST Nexdox">
//   Copyright (c) DST Nexdox. All rights reserved.
// </copyright>
// <summary>
//   Defines the MailSortSettingRepository type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DocProcessingRepository.Repositories
{
  using System;
  using System.Collections.Generic;
  using System.Data.SqlClient;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using DocProcessingRepository.Contexts;
  using DocProcessingRepository.Interfaces;
  using EFRepository;
  using Entities;

  public class MailSortSettingRepository : BaseEfRepository<MailsortSetting>, IMailSortSettingRepository
  {
    public MailSortSettingRepository(String connectionString)
      : base(new IdentityDb(connectionString))
    {
    }

    public List<MailsortSetting> GetMailsortSettings()
    {
      List<MailsortSetting> mailSortSettings =
        this.GetEntityListByStoreProcedure<MailsortSetting>("exec GetMailSortSettings")
        .ToList();

      return mailSortSettings;
    }

    public MailsortSetting AddMailSortSetting(
      String tntDepot,
      String tntMailingHouse,
      String tntClientCode,
      String tntJobReference,
      String nexdoxMailsortService,
      Boolean largeLetter,
      Int32? fixedWeightNoOuter)
    {
      MailsortSetting addedMailSortSetting = this.GetEntityListByStoreProcedure<MailsortSetting>(
        "AddMailSortSetting @TNTDepot, @TNTMailingHouse, @TNTClientCode, @TNTJobReference, @NexdoxMailSortService, @LargeLetter, @FixedWeightNoOuter",
        new SqlParameter("@TNTDepot", (Object)tntDepot ?? DBNull.Value),
        new SqlParameter("@TNTMailingHouse", (Object)tntMailingHouse ?? DBNull.Value),
        new SqlParameter("@TNTClientCode", (Object)tntClientCode ?? DBNull.Value),
        new SqlParameter("@TNTJobReference", (Object)tntJobReference ?? DBNull.Value),
        new SqlParameter("@NexdoxMailSortService", (Object)nexdoxMailsortService ?? DBNull.Value),
        new SqlParameter("@LargeLetter", largeLetter),
        new SqlParameter("@FixedWeightNoOuter", fixedWeightNoOuter.HasValue ? (Object)fixedWeightNoOuter.Value : DBNull.Value))
      .Single();

      return addedMailSortSetting;
    }
  }
}
